home *** CD-ROM | disk | FTP | other *** search
- /* BleuRoseErrors.c - This file defines the interface to
- the Bleu Rose Ltd. Error Library
-
- Copyright 2000 Bleu Rose Ltd. All Rights Reserved.
-
- Author: Gary Rice
-
- Created: September 9, 2000 - Original development environment:
- CodeWarrior/Pro v5.3
- Mac OS v7.6.1
-
- Modified: N/A
-
- Licensing Notes:
- You may incorporate this source code into your
- applications without restriction.
-
- You are NOT permitted to redistribute the source,
- compiled binaries or the library that the code
- references without first licensing the package
- represented by this source file from Bleu Rose Ltd.
-
- Licensing information was packaged with the files
- that this file was part of. If that licensing information
- is no longer included in the files you have, you may obtain
- another copy by sending EMail to licensing@bleurose.com
- and asking for the Error Library Licensing Package.
-
- Usage Notes:
- Refer to the sample file "main.c" for an example of how
- to use these routines.
-
- The efficiency of these routines can be improved by adding
- code that saves the code resource in memory rather than
- locating and loading the code resource each time the routines
- are accessed.
-
- ******************************************************************/
-
- #include <SegLoad.h>
-
- #include "BleuRoseErrors.h"
-
- /****************************************************************
- Routine: FindBleuRoseErrorLibrary
- Purpose: Locates the Bleu Rose Ltd. Error Library so that it can
- be accessed as a code resource
- Algorithm: Attempt to locate the BleuRoseErrorLib code resource in:
- 1) Your application
- 2) The same folder as your application (in a separate file
- called BleuRoseErrorLib)
- 3) Extensions folder as a separate file called BleuRoseErrorLib
- Inputs: None
- Outputs: A pointer to the FSSpec for BleuRoseErrorLib - If the resource
- is included in the application itself, the FSSpec will be empty
- but the status returned will be "noErr"
- Status: 0 = noErr Success
- -43 = fnfErr Could not locate the Error Library
- -192 = resNotFound
- Could not locate the Error Library Code Resource
- Any other error returned by ResError ()
- -2147483644 = kErrorResMissing
- The error TEXT resource is missing. */
-
- OSStatus FindBleuRoseErrorLibrary (FSSpecPtr theLibrary)
- {
- Handle libraryRes = nil;
- FCBPBRec paramBlock;
- Str31 appName;
- FSSpec tmpFile;
- OSStatus result = (OSStatus)noErr;
- long resSize;
- long foundDirID;
- short foundVRefNum;
- short libraryResNum;
- short saveCurResFileRefNum = CurResFile ();
-
- /* Make sure we start with a clean data structure */
- theLibrary->vRefNum = 0;
- theLibrary->parID = 0;
- theLibrary->name[0] = 0;
-
- /* Test for CurResFile errors */
- result = (OSStatus)ResError ();
- if (result)
- return result;
-
- /* Convert the refnum of the app into an FSSpec */
- libraryResNum = LMGetCurApRefNum ();
- paramBlock.ioCompletion = nil;
- paramBlock.ioNamePtr = appName;
- paramBlock.ioVRefNum = 0;
- paramBlock.ioRefNum = libraryResNum;
- paramBlock.ioFCBIndx = 0;
- result = (OSStatus)PBGetFCBInfo (¶mBlock, false);
- if (result)
- return result;
-
- /* Look inside the current application for the library first */
- result = FSMakeFSSpec (paramBlock.ioFCBVRefNum, paramBlock.ioFCBParID, appName, &tmpFile);
- if (result)
- return result;
-
- /* Look for the main error resource */
- UseResFile (libraryResNum);
- libraryRes = Get1Resource (kBleuRoseErrorLibListType, kBleuRoseErrorLibCommonResID);
- if (!libraryRes)
- result = (OSStatus)resNotFound;
- else
- result = (OSStatus)ResError ();
-
- /* If we got this resource assume that the library is inside the application.
- If the size isn't reasonable, assume that the library has not been populated. */
- if (result == (OSStatus)noErr)
- {
- resSize = GetResourceSizeOnDisk (libraryRes);
- if (resSize < kEstimatedErrorResSize)
- {
- /* Reset to what we started with */
- UseResFile (saveCurResFileRefNum);
- return (kErrorResMissing);
- }
- }
-
- /* If the application doesn't have the error library
- inside, look for it in the application's folder
- as a stand-alone file */
- if (result)
- {
- /* open the resource fork of the Error Library */
- BlockMoveData (kBleuRoseErrorLibFileName, tmpFile.name, 17);
- libraryResNum = FSpOpenResFile (&tmpFile, fsRdPerm);
- if (libraryResNum != -1) /* Must have found a file */
- {
- /* Look for the main error resource */
- UseResFile (libraryResNum);
- libraryRes = Get1Resource (kBleuRoseErrorLibListType, kBleuRoseErrorLibCommonResID);
- if (!libraryRes)
- result = (OSStatus)resNotFound;
- else
- result = (OSStatus)ResError ();
-
- /* If we got this resource assume that the library is inside the application.
- If the size isn't reasonable, assume that the library has not been populated. */
- if (result == (OSStatus)noErr)
- {
- resSize = GetResourceSizeOnDisk (libraryRes);
- if (resSize < kEstimatedErrorResSize)
- {
- /* Reset to what we started with */
- UseResFile (saveCurResFileRefNum);
- return (kErrorResMissing);
- }
- }
-
- /* If everything is OK, set up the library FSSpec */
- if (result == (OSStatus)noErr)
- {
- BlockMoveData (tmpFile.name, theLibrary->name, tmpFile.name[0]+1);
- theLibrary->vRefNum = tmpFile.vRefNum;
- theLibrary->parID = tmpFile.parID;
- }
-
- CloseResFile (libraryResNum);
- }
- else /* No file in this directory */
- {
- result = (OSStatus)ResError ();
- if (result == (OSStatus)noErr)
- result = (OSStatus)resNotFound;
- }
- }
-
- /* If the application folder doesn't have the error library inside,
- look for it in the Extensions folder as a stand-alone file */
- if (result)
- {
- /* Get the Extensions folder volume and directory info */
- result = (OSStatus)FindFolder (kOnSystemDisk, kExtensionFolderType, kDontCreateFolder,
- &foundVRefNum, &foundDirID);
- if (result == (OSStatus)noErr)
- {
- /* Turn the Extensions info into an FSSpec */
- result = (OSStatus)FSMakeFSSpec (foundVRefNum, foundDirID, kBleuRoseErrorLibFileName,
- &tmpFile);
- if (result == (OSStatus)noErr)
- {
- /* open the resource fork of the Error Library */
- libraryResNum = FSpOpenResFile (&tmpFile, fsRdPerm);
- if (libraryResNum != -1) /* Must have found a file */
- {
- /* Look for the main error resource */
- UseResFile (libraryResNum);
- libraryRes = Get1Resource (kBleuRoseErrorLibListType, kBleuRoseErrorLibCommonResID);
- if (!libraryRes)
- result = (OSStatus)resNotFound;
- else
- result = (OSStatus)ResError ();
-
- /* If we got this resource assume that the library is inside the application.
- If the size isn't reasonable, assume that the library has not been populated. */
- if (result == (OSStatus)noErr)
- {
- resSize = GetResourceSizeOnDisk (libraryRes);
- if (resSize < kEstimatedErrorResSize)
- {
- /* Reset to what we started with */
- CloseResFile (libraryResNum);
- UseResFile (saveCurResFileRefNum);
- return (kErrorResMissing);
- }
- }
-
- /* If everything is OK, set up the library FSSpec */
- if (result == (OSStatus)noErr)
- {
- BlockMoveData (tmpFile.name, theLibrary->name, tmpFile.name[0]+1);
- theLibrary->vRefNum = tmpFile.vRefNum;
- theLibrary->parID = tmpFile.parID;
- }
-
- CloseResFile (libraryResNum);
- }
- else /* No file in this directory */
- {
- result = (OSStatus)ResError ();
- if (result == (OSStatus)noErr)
- result = (OSStatus)resNotFound;
- }
- }
- }
- }
-
- /* Reset to what we started with */
- UseResFile (saveCurResFileRefNum);
- return (result);
- } /* FindBleuRoseErrorLibrary */
-
- /****************************************************************
- Routine: CallBleuRoseErrorLibrary
- Purpose: - Look up an error number in the database
- - Translate an error type number into its equivalent
- error type name such as "QuickTime".
- Algorithm: Using the proposed error type as a basis, find the error that corresponds
- to the error and type specified. If there is no match for the error type
- but the error number itself is found, return the first occurrence of the
- error in the database plus a warning status. Otherwise return an error.
-
- If translating an error type number into its equivalent, Access STR# resource
- 29271 (kBleuRoseErrorLibCommonResID) to translate the number into a name.
- Inputs: An FSSpec pointer connected to a valid FSSpec for the error library.
- and
- A BleuRoseErrorLibStructure pointer connected to a valid
- BleuRoseErrorLibStructure filled in as follows:
- Out-In Name Type Description
- -> action SInt32 Set to kGetError for getting an error code
- or
- Set to kGetType for translating an error type
- into a string. For this option, the following
- fields are not used (and may be left blank):
- error
- actualErrorTypeNumber
- pneumonic
- description
- -> error SInt32 The error number to look up
- -> proposedErrorTypeNumber SInt16 The Error Type value to try
- <- actualErrorTypeNumber SInt16 The Error Type value matching the error found
- <- errorTypeName Str255 Name string matching the Error Type number
- <- pneumonic Str255 Apple's name for this error
- <- description Str255 Apple's explanation of this error
-
- The proposedErrorTypeNumber value is a number from 0 (k1stErrorTypeFound) through
- kZlastType-1. Constants are defined in "BleuRoseErrors.h" for each of the error
- types in the database.
- Outputs: See above
- Status: 0 = noErr Success
- -43 = fnfErr Could not find the Error Library
- -109 = nilHandleErr
- Could not find the code resource in the Error Library
- 2147483646 = kWarningErrorNotDescribed
- The error was on file but contained no explanation.
- A substitute explanation string was used.
- 2147483643 = kWarningErrorNotRequestedType
- There was an error on file but it doesn't match the
- type of error you specified. The error entry has been
- filled in with the information about the error that
- was found.
- 2147483645 = kWarningErrorNotDescribedAndNotRequestedType
- Both warnings (above) apply.
- -2147483646 = kErrorTypeResMissing
- The error type STR# resource 21077 is missing
- -2147483647 = kErrorTypeNotOnFile
- The error type you specified is not on file
- in the database. The type value must be from
- 0 (k1stErrorTypeFound) <= type value < kZlastType
- -2147483648 = kErrorNotOnFile
- The error number you supplied is not on file in
- the database. */
-
- OSStatus CallBleuRoseErrorLibrary (FSSpecPtr theLibrary, BleuRoseErrorLibStructurePtr errorInfo)
- {
- OSStatus status;
- Handle codeRes = nil;
- short libraryResNum = 0;
- short saveCurResFileRefNum = 0;
-
- /* If the FSSpec has been filled in, assume that the code resource is in a separate file
- and NOT part of the current application */
- if (theLibrary->name[0] != 0)
- {
- saveCurResFileRefNum = CurResFile ();
- /* open the resource fork of the Error Library */
- libraryResNum = FSpOpenResFile (theLibrary, fsRdPerm);
- if (libraryResNum == -1) /* Must have had a problem */
- {
- status = (OSStatus)ResError ();
- return status;
- }
-
- UseResFile (libraryResNum);
- }
-
- /* Load the code resource */
- codeRes = Get1Resource (kBleuRoseErrorLibResType, kBleuRoseErrorLibCommonResID);
- if (codeRes)
- {
- /* Lock the resource in high memory and execute it */
- HLockHi (codeRes);
- status = CallBleuRoseErrorLibProc ((BleuRoseErrorLibProcUPP)*codeRes, errorInfo);
- HUnlock (codeRes);
- }
- else /* Oops. No code resource */
- {
- status = (OSStatus)ResError ();
- if (!status)
- status = (OSStatus)nilHandleErr;
- }
-
- /* If the library was in a separate file, close it */
- if (libraryResNum)
- CloseResFile (libraryResNum);
-
- /* Reset the environment */
- if (saveCurResFileRefNum)
- UseResFile (saveCurResFileRefNum);
-
- return status;
- } /* CallBleuRoseErrorLibrary */